package com.taotao.test2.config;

import io.minio.MinioClient;
import io.minio.errors.InvalidEndpointException;
import io.minio.errors.InvalidPortException;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @program: test2
 * @ClassName MinioConfig
 * @description: 编写配置类
 * @author: wangjin
 * @create: 2023-11-03 17:23
 * @Version 1.0
 **/
@Data
@Configuration
//加载yml文件中以minio开头的配置项
@ConfigurationProperties(prefix = "minio")
public class MinioConfig {
    /*会自动的对应配置项中对应的key*/
    private String endpoint;//minio.endpoint
    private String accessKey;
    private String secretKey;
    private Integer port;

    @Bean
    public MinioClient getMinioClient() throws InvalidPortException, InvalidEndpointException {

        MinioClient minioClient = new MinioClient(getEndpoint(), getPort(), getAccessKey(), getSecretKey(), false);
        return minioClient;
    }

}
